1 00:00:00,600 --> 00:00:05,890 Hello and welcome to the part two of adding javascript to our prayer. 2 00:00:05,970 --> 00:00:14,340 The next thing I want to do is create a function that will allow the mall to peek is head out of the 3 00:00:14,640 --> 00:00:15,070 mall. 4 00:00:15,080 --> 00:00:16,090 He'll survive. 5 00:00:16,110 --> 00:00:18,250 Click on this start. 6 00:00:18,300 --> 00:00:23,910 Here you see the head popping up so that's what we're trying to achieve something to create the function 7 00:00:24,420 --> 00:00:25,990 that will achieve that. 8 00:00:26,400 --> 00:00:37,080 I have added the function called Peep So this is the function down allow the more to keep its head out 9 00:00:37,170 --> 00:00:38,870 of the mole hill. 10 00:00:39,110 --> 00:00:47,400 So I've created some constants here constant time I called it time and I've set it to cause to run some 11 00:00:47,400 --> 00:00:55,400 time and a past to a time of this is a millisecond This is 200 milliseconds. 12 00:00:55,400 --> 00:00:59,380 And this is one this is 10 seconds. 13 00:00:59,580 --> 00:01:00,480 Okay. 14 00:01:01,050 --> 00:01:06,600 So we've got the random time here which we are using from the random time function. 15 00:01:06,600 --> 00:01:13,480 So we are calling the random time function here passing it values in many seconds. 16 00:01:13,660 --> 00:01:21,090 Okay here we've got variable here constant again chord hall and we are setting that to cause the random 17 00:01:21,380 --> 00:01:26,950 function how inside that is taking in the perimeters for the calls. 18 00:01:26,960 --> 00:01:36,720 And here we are in a class there's a csx class which will be called this physically here will trigger 19 00:01:36,900 --> 00:01:37,490 the CSA. 20 00:01:37,500 --> 00:01:41,940 So if you look inside this here's a how to get to class here quad up. 21 00:01:42,000 --> 00:01:44,370 So that's what that is referring to. 22 00:01:44,370 --> 00:01:48,810 So it's adding that on to that success. 23 00:01:49,020 --> 00:01:54,100 And we're set in a time out because we don't want it to pick his head out forever. 24 00:01:54,360 --> 00:01:57,570 So this time out we use our function here. 25 00:01:57,720 --> 00:02:00,300 So grunt's is picked to serve. 26 00:02:01,110 --> 00:02:04,050 The time has elapsed. 27 00:02:04,050 --> 00:02:11,640 It will remove this csx It will remove the class and if it tells you here that this condition statement 28 00:02:11,760 --> 00:02:19,430 if the time is up it will call the pip function which is this function here or so for the time. 29 00:02:19,600 --> 00:02:24,950 So to begin with the time is set to be false. 30 00:02:25,020 --> 00:02:29,580 You can see here we've got the let's statements end time up is false. 31 00:02:29,580 --> 00:02:35,370 So to begin it would be start to be false and then later it it'll be. 32 00:02:35,370 --> 00:02:41,130 Once the time elapses that condition is no longer true. 33 00:02:41,580 --> 00:02:48,110 Next I want to do is create the function that will start the game. 34 00:02:48,180 --> 00:02:50,730 So again I priest t could hear. 35 00:02:50,730 --> 00:02:57,600 So this is the function that will be used to start the game. 36 00:02:57,780 --> 00:03:05,720 So on line 6 AM added a letter statement for the score and the default score which will be zero. 37 00:03:06,000 --> 00:03:12,530 So if I go back in to my start game function this is the function that will start the game. 38 00:03:12,750 --> 00:03:21,090 So when you click on the button it will trigger this function and when the function runs a tool set 39 00:03:21,170 --> 00:03:29,610 the scoreboard to zero and the initial time warp is going to be false so you can see here we'll call 40 00:03:29,640 --> 00:03:32,130 the time OP statement is false. 41 00:03:32,130 --> 00:03:39,420 Initially it will be false and the score also will be set to zero and then to start the game by calling 42 00:03:39,420 --> 00:03:45,050 this peep function where the mall would -- outside of this hall. 43 00:03:45,060 --> 00:03:50,660 Each of the holes randomly switch to a randomly pick is said out of Iran them all. 44 00:03:50,940 --> 00:03:56,250 However when the time lapses is all it has 10 seconds to do that. 45 00:03:56,490 --> 00:04:05,310 So when that 10 seconds elapse is this set time out is called and the Time War is no longer of force 46 00:04:05,490 --> 00:04:13,590 this time of value becomes true when that 10 seconds has elapsed final function. 47 00:04:13,590 --> 00:04:18,520 I want to add is some implementation of scoring here. 48 00:04:18,700 --> 00:04:27,400 So right up here I have got on I've got the initial score here set to zero. 49 00:04:27,690 --> 00:04:30,580 So this is a function I've just had it here. 50 00:04:30,600 --> 00:04:36,890 I've created a function called it whack t the e is basically the event. 51 00:04:36,900 --> 00:04:43,520 What this will do exactly is that when the mall picks his head out of the molehill. 52 00:04:43,620 --> 00:04:48,130 The goal here is to try and click on it or whack it with your mouse. 53 00:04:48,390 --> 00:04:55,860 And if you are able to do that it disk it will give it a point which this is it all changed the value 54 00:04:55,890 --> 00:04:58,510 of the score variable plus blows me. 55 00:04:58,520 --> 00:04:59,890 It would increase the value. 56 00:05:00,100 --> 00:05:00,610 1. 57 00:05:00,750 --> 00:05:07,040 So for every successful whack of the mall when he picks his head out you get one point. 58 00:05:07,050 --> 00:05:08,100 This here will go. 59 00:05:08,280 --> 00:05:13,740 If he was referring to this event is trusted to a return. 60 00:05:13,770 --> 00:05:24,030 This is this is trusted here basically is an event property that returns the bullion value indicating 61 00:05:24,030 --> 00:05:26,110 where the event is. 62 00:05:26,220 --> 00:05:33,610 Did not so if someone is trying to cheat by not actually go into the right process thus Ward this this 63 00:05:33,610 --> 00:05:35,440 or it will return. 64 00:05:35,670 --> 00:05:38,420 Okay so this bullion is. 65 00:05:38,460 --> 00:05:40,490 Is it true or false value. 66 00:05:40,830 --> 00:05:46,800 So if these give the value of that is trust to property it's a bulimba I leave it to indicate whether 67 00:05:46,800 --> 00:05:49,650 the event is trusted or not. 68 00:05:49,660 --> 00:05:56,850 So each time you successfully whack the mall when he picks his head out this score count will increase 69 00:05:56,850 --> 00:06:01,730 to 1 using this plus plus And then what happens. 70 00:06:01,770 --> 00:06:08,640 This keyword this refers to the current instance the actual parent node. 71 00:06:08,750 --> 00:06:12,590 It will then remove this class. 72 00:06:12,790 --> 00:06:17,550 Okay so this here is reference to inside this vss. 73 00:06:17,910 --> 00:06:19,330 Alright so we to remove this. 74 00:06:19,340 --> 00:06:22,600 Classes are the same says clout who did it would then remove it. 75 00:06:22,710 --> 00:06:30,180 Once you've successfully whacked it and then this core board content will set to the current score so 76 00:06:30,180 --> 00:06:32,390 each time you successfully whack it. 77 00:06:32,580 --> 00:06:38,040 This is what will happen and then the score board will change like 50. 78 00:06:38,040 --> 00:06:43,700 Basically what we're seeing here for each of the mall that you whack. 79 00:06:44,010 --> 00:06:47,800 We add in an event who I missed out. 80 00:06:48,450 --> 00:06:52,540 Okay I missed this close in parenthesis here. 81 00:06:52,600 --> 00:07:02,220 Right so here for each of the more we are attached in an event list now so this add listener basically 82 00:07:02,220 --> 00:07:09,870 allows you to listen out for an event and event is listening not for is the click event so each time 83 00:07:09,870 --> 00:07:18,640 we're able to click to work more by clicking on it with the mouse to trigger this function called Whack. 84 00:07:18,690 --> 00:07:25,620 That's basically what that is is calling it a reference this function when we're able to successfully 85 00:07:26,040 --> 00:07:31,920 click on the Mall talk whack it is in our using the click of the mouse. 86 00:07:31,920 --> 00:07:36,180 So that's basically a project completed. 87 00:07:36,180 --> 00:07:39,780 With this he says obviously you can improve on this projet. 88 00:07:39,990 --> 00:07:41,150 There's a lot you can do. 89 00:07:41,160 --> 00:07:51,360 You can add a process that will retain the previous score or keep a score higher score and still you 90 00:07:51,360 --> 00:07:54,640 can also there's a lot you can do to improve on the game. 91 00:07:54,680 --> 00:07:58,970 I'm going to save that and then we can run it and test the whole game. 92 00:07:59,370 --> 00:08:04,670 So I'm going to run by clicking on the index FAQ here. 93 00:08:06,690 --> 00:08:09,990 And just click on the start button. 94 00:08:10,170 --> 00:08:15,860 So the goal here is to try and whack the mall as he puts his head out of the hole. 95 00:08:16,060 --> 00:08:22,130 So start so I click on start to see go on points. 96 00:08:22,600 --> 00:08:25,550 I've got 10 seconds to do this. 97 00:08:25,950 --> 00:08:29,930 See Okay I'm not doing too bad here. 98 00:08:30,120 --> 00:08:35,760 See I got three points only 10 seconds after lap so if I start again and then the process begins again 99 00:08:35,770 --> 00:08:40,710 so that's basically the game complete at a it. 100 00:08:40,710 --> 00:08:43,040 Thanks for watching and bye for now.